<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text"id="i1"placeholder="请输入0-100的整数">
<input type="button"value="猜一猜"onclick="fn()">
<div id="d1"></div>
<script>
    /*生成一个0-100的随机数*/
let x=parseInt(Math.random()*101);
let count=0//记录猜的次数
function fn() {
    if (isNaN(i1.value.trim())||i1.value.trim()==''){
        d1.innerText='输入错误!'
        return
    }
    count++
if (i1.value<x){
    d1.innerText='对不起,你猜小了'
}else if (i1.value>x){
    d1.innerText='对不起,你猜大了'
}else {
    d1.innerText='恭喜你,第'+count+'次猜对了'
}
}
</script>
</body>
</html>